

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/boshi.jpeg">
  <link rel="icon" type="image/png" href="/img/boshi.jpeg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="wangpf">
  <meta name="keywords" content="">
  <title>React学习总结（一）：组件 - wpf的博客</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/foundation.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_6peoq002giu.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.1.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Wangpf's blog</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/article.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2021-01-24 16:30" pubdate>
      2021年1月24日 下午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      751 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      10
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">React学习总结（一）：组件</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="前言，"><a href="#前言，" class="headerlink" title="前言，"></a>前言，</h2><p>好久没学习了，现在正式开始学习React啦~</p>
<p>之前有大概了解过React，了解过React的实现原理，所以我打算直接从 <code>组件</code> 来开始我的React学习之旅</p>
<h2 id="元素与组件"><a href="#元素与组件" class="headerlink" title="元素与组件"></a>元素与组件</h2><p><strong>React元素：</strong></p>
<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-keyword">const</span> div = React.createElement(<span class="hljs-string">&quot;div&quot;</span>,...)</code></pre></div>
<p><strong>React组件：</strong></p>
<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-keyword">const</span> Div = <span class="hljs-function">() =&gt;</span> React.createElement(<span class="hljs-string">&quot;div&quot;</span>,...)</code></pre></div>

<p>元素和组件的区别就在于 组件必须返回的是一个函数，并且命名首字母要大写！</p>
<h2 id="什么是组件"><a href="#什么是组件" class="headerlink" title="什么是组件"></a>什么是组件</h2><ul>
<li>用生活中的例子就是：能和其他物件组合在一起的物件就是组件，</li>
<li>比如Vue中，一个构造选项就可以表示一个组件。</li>
<li>在React官方中说到，组件的本质就是JavaScript函数</li>
</ul>
<h2 id="React的俩种组件：函数组件与-class-组件"><a href="#React的俩种组件：函数组件与-class-组件" class="headerlink" title="React的俩种组件：函数组件与 class 组件"></a>React的俩种组件：函数组件与 class 组件</h2><h3 id="函数组件"><a href="#函数组件" class="headerlink" title="函数组件"></a>函数组件</h3><div class="hljs"><pre><code class="hljs jsx"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Welcome</span>(<span class="hljs-params">props</span>) </span>&#123;
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello, &#123;props.name&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;
&#125;</code></pre></div>
<p>使用方法：</p>
<div class="hljs"><pre><code class="hljs jsx">&lt;Welcome name=<span class="hljs-string">&quot;Wangpf&quot;</span>/&gt;</code></pre></div>

<h3 id="class组件"><a href="#class组件" class="headerlink" title="class组件"></a>class组件</h3><div class="hljs"><pre><code class="hljs jsx"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Welcome</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>&#123;
  render() &#123;
    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello, &#123;this.props.name&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;
  &#125;
&#125;</code></pre></div>

<p>使用方法：</p>
<div class="hljs"><pre><code class="hljs jsx">&lt;Welcome name=<span class="hljs-string">&quot;Wangpf&quot;</span>/&gt;</code></pre></div>

<p>上述两个组件在 React 里是等效的。</p>
<h2 id="那么-lt-Welcome-gt-会被翻译为-React-createElement-…"><a href="#那么-lt-Welcome-gt-会被翻译为-React-createElement-…" class="headerlink" title="那么 &lt;Welcome /&gt; 会被翻译为 React.createElement(….)"></a>那么 <code>&lt;Welcome /&gt;</code> 会被翻译为 React.createElement(….)</h2><p>我用 <a href="">babel online</a> 来演示一下</p>
<p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6d2403f697f743368bb78407ca93aeea~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" alt="div"></p>
<p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/07c31ac5fbe244b6af0067981296c440~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" alt="&lt;Welcome /&gt;"></p>
<p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d1b77403eae0408ea6cb176db8a0adbc~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" alt="&lt;Welcome /&gt;"></p>
<p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/47683cc38e314d7fb7717ff5ebe1e423~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" alt="&lt;Welcome /&gt;"></p>
<p>总结：</p>
<ol>
<li>如果传入的是一个<code>字符串</code>：比如 “div”，则会去创建一个div</li>
<li>如果传入的是一个<code>函数</code>，则会去调用该函数，<code>获取其返回值</code></li>
<li>如果传入的是一个<code>类</code>，则会在类前面加个 new（这会导致执行constructor），获取一个组件对象，然后调用对象的render方法，<code>获取其返回值</code></li>
</ol>
<h2 id="小试牛刀"><a href="#小试牛刀" class="headerlink" title="小试牛刀"></a>小试牛刀</h2><p><strong>分别用俩种组件方式来写props(外部数据，传参)、state（内部数据）：</strong></p>
<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;react&#x27;</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;./style.css&quot;</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>&#123;
  <span class="hljs-keyword">return</span> (
    &lt;div className=<span class="hljs-string">&quot;App&quot;</span>&gt;
      父组件
      &lt;Son messageForSon=<span class="hljs-string">&quot;我是你的老大&quot;</span> /&gt;
    &lt;/div&gt;
  );
&#125;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Son</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>&#123;
  <span class="hljs-keyword">constructor</span>() &#123;
    <span class="hljs-built_in">super</span>()
    <span class="hljs-built_in">this</span>.state = &#123;
      n: <span class="hljs-number">0</span>
    &#125;
  &#125;

  render() &#123;
    <span class="hljs-keyword">return</span> (
      &lt;div className=<span class="hljs-string">&quot;Son&quot;</span>&gt;
        子组件
        &lt;span&gt; n: &#123;<span class="hljs-built_in">this</span>.state.n&#125; &lt;/span&gt;
        &lt;button onClick=&#123;<span class="hljs-function">() =&gt;</span> &#123; <span class="hljs-built_in">this</span>.add() &#125;&#125;&gt; +<span class="hljs-number">1</span>&lt;/button&gt;
        &lt;p&gt;我是子组件，父组件对我说：&#123;<span class="hljs-built_in">this</span>.props.messageForSon&#125;&lt;/p&gt;
        &lt;Grandson messageForGrandson=<span class="hljs-string">&quot;我是你的老大,你是我老大的孙子&quot;</span> /&gt;
      &lt;/div&gt;
    )
  &#125;

  add() &#123;
    <span class="hljs-comment">// this.setState(&#123;</span>
    <span class="hljs-comment">//   n: this.state.n + 1</span>
    <span class="hljs-comment">// &#125;)</span>

    <span class="hljs-built_in">this</span>.setState(<span class="hljs-function"><span class="hljs-params">state</span> =&gt;</span> &#123;
      <span class="hljs-keyword">const</span> n = state.n + <span class="hljs-number">1</span>
      <span class="hljs-comment">// console.log(n);</span>
      <span class="hljs-keyword">return</span> &#123; n &#125;
    &#125;)
  &#125;
 &#125;

<span class="hljs-keyword">const</span> Grandson = <span class="hljs-function">(<span class="hljs-params">props</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">const</span> [n, setN] = React.useState(<span class="hljs-number">0</span>)
  <span class="hljs-keyword">return</span> (
    &lt;div className=<span class="hljs-string">&quot;Grandson&quot;</span>&gt;
      孙组件
      &lt;span&gt; n : &#123;n&#125; &lt;/span&gt;
      &lt;button onClick=&#123;<span class="hljs-function">() =&gt;</span> &#123; setN(n + <span class="hljs-number">1</span>) &#125;&#125;&gt; +<span class="hljs-number">1</span>&lt;/button&gt;
      &lt;p&gt;我是孙组件，子组件对我说：&#123;props.messageForGrandson&#125;&lt;/p&gt;
    &lt;/div&gt;
  )
&#125;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App</code></pre></div>
<p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/edfe90e98e6d482baad5706cf115978e~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" alt="俩种组件的书写方式"></p>
<h3 id="总结："><a href="#总结：" class="headerlink" title="总结："></a>总结：</h3><p><strong>使用props（外部数据）</strong></p>
<ul>
<li>类组件 会直接读取<code>属性</code> this.props.xxx</li>
<li>函数组件 会直接读取<code>参数</code> props.xxx</li>
</ul>
<p><strong>使用state（内部数据）</strong></p>
<ul>
<li>类组件 用 this.state 读，  this.setState 写</li>
<li>函数组件 用 useState 返回数组，第一项是读， 第二项是写<ul>
<li>const [n, setN] = React.useState(0) </li>
</ul>
</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                <div class="post-meta mr-3">
                  <i class="iconfont icon-category"></i>
                  
                  <a class="hover-with-bg" href="/categories/React/">React</a>
                  
                </div>
                
                
                <div class="post-meta">
                  <i class="iconfont icon-tags"></i>
                  
                  <a class="hover-with-bg" href="/tags/React/">React</a>
                  
                </div>
                
              </div>
              
              
              <div class="post-prevnext row">
                <article class="post-prev col-6">
                  
                  
                  <a href="/2021/01/26/48-%E8%99%9A%E6%8B%9FDOM/">
                    <i class="iconfont icon-arrowleft"></i>
                    <span class="hidden-mobile">虚拟DOM和diff算法以及关于key的问题（学习总结）</span>
                    <span class="visible-mobile">上一篇</span>
                  </a>
                  
                </article>
                <article class="post-next col-6">
                  
                  
                  <a href="/2021/01/09/45-Docker%20%E5%AE%89%E8%A3%85/">
                    <span class="hidden-mobile">node.js中使用nodemailer插件发送邮件 (学习总结)</span>
                    <span class="visible-mobile">下一篇</span>
                    <i class="iconfont icon-arrowright"></i>
                  </a>
                  
                </article>
              </div>
              
            </div>

            
            <!-- Comments -->
            <article class="comments" id="comments">
              
              
  <div id="vcomments"></div>
  <script type="text/javascript">
    function loadValine() {
      addScript('https://cdn.staticfile.org/valine/1.4.14/Valine.min.js', function () {
        new Valine({
          el: "#vcomments",
          app_id: "hjxsDRXYScicliqD8I8JqoTu-gzGzoHsz",
          app_key: "qUcAEReEqeEVp5wwXJ41uCCp",
          placeholder: "说点什么",
          path: window.location.pathname,
          avatar: "retro",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: true,
          recordIP: false,
          serverURLs: "",
        });
      });
    }
    waitElementVisible('vcomments', loadValine);
  </script>
  <noscript>Please enable JavaScript to view the <a target="_blank" href="https://valine.js.org" rel="nofollow noopener noopener">comments
      powered by Valine.</a></noscript>


            </article>
            
          </article>
        </div>
      </div>
    </div>
    
    <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
      <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

    </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    
      <script  src="/js/lazyload.js" ></script>
    
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "React学习总结（一）：组件&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "always",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  











  

  

  

  

  

  





</body>
</html>
